"""
keyword： 关键字
False None True and break continue class def
elif else for global nonlocal  if import in is lambda
not or  pass return while
"""
import keyword
import random
# print(len(keyword.kwlist))
# for kw in keyword.kwlist:
#     print(kw)


# import random
# print(random)
# # 固定随机种子  伪随机  指定随机算法 获取随机结果就一样了
# # random.seed(1)
#
# #  返回一个[0, 1) 的浮点数
# print(random.random())
# #  返回数字 包含[a, b]
# print(random.randint(10, 15))
# # n 选 1
# print(random.choice(["西红柿炒鸡蛋", "番茄炒鸡蛋", "意大利面"]))
# # n 选 k 个
# print(random.sample(["西红柿炒鸡蛋", "番茄炒鸡蛋", "意大利面"], k=2))
# # n 选 k个 可以重复
# print(random.choices(["西红柿炒鸡蛋", "番茄炒鸡蛋", "意大利面"], k=2))
# # 从range的结果随机一个数字
# print(random.randrange(1, 5, 2))
#
# # 洗牌函数  随机打乱顺序
# l = [x for x in range(10)]
# random.shuffle(l)
# print(l)
#
#
# # 使用面向对象实例写法
# r = random.Random()
# r.seed(1)
# print(r.random())
# print(r.randint(10, 20))
# print(r.randrange(10, 20, 3))


# import datetime
# print(datetime)
# from datetime import date, time, datetime, timedelta
#
# # 构造日期
# today = date.today()
# print(today, today.year, today.month, today.day, today.strftime("%Y年%m月%d日"))
# yestaday = date(year=2024, month=6, day=4)
# print(yestaday, yestaday.year, yestaday.month, yestaday.day, yestaday.strftime("%Y年%m月%d日"))
# tomarrow = date(2024, month=6, day=6)
# print(tomarrow, tomarrow.year, tomarrow.month, tomarrow.day, tomarrow.strftime("%Y年%m月%d日"))
# print("-----------------------------")
# # 构造时间
# now_time = time(hour=16, minute=29, second=30)
# print(now_time, now_time.hour, now_time.minute, now_time.second, now_time.strftime("%H时%M分%S秒"))
# print("-----------------------------")
# # # 构造日期时间
# now = datetime.now()
# print(now, now.year, now.month, now.day, now.hour, now.minute, now.second, now.strftime("%y/%m/%d %H:%M:%S"))
# tomarrow_now = datetime(year=2024, month=6, day=6, hour=16, minute=33)
# print(tomarrow_now, tomarrow_now.year, tomarrow_now.month, tomarrow_now.day, tomarrow_now.hour, tomarrow_now.minute, tomarrow_now.second,now.strftime("%Y-%m-%d %H:%M:%S"))


# now = datetime.now()
# #   一百天后
# target = now + timedelta(days=100)
#
# # 三天后
# target2 = target - timedelta(days=97)
# print(target, target2)
#
# # 7天后
# target3 = now + timedelta(weeks=1, hours=2, seconds=30)
# print(target3)


# import time
# # 时间戳
# start = time.time()
# # print(start)
# # datas = []
# # for i in range(10000000):
# #     value = random.randint(1, 100000000)
# #     datas.append(value)
# # datas.sort()
#
# # 程序等待10s
# time.sleep(10)

# end = time.time()
# print(f"时间开销：{end - start}")


import sys
# print(sys)

# # print(sys.path)
# sys.path.append("E:\\")
# for path in sys.path:
#     print(path)
#
# import test0
# print(test0.PI, test0.G)

# sys.getrecursionlimit()
# sys.setrecursionlimit(2000)


import os
# print(os)

# if not os.path.exists("myfolder"):
#     os.mkdir("myfolder")
# else:
#     os.rmdir("myfolder")

# for filename in os.listdir("./heads"):
# for filename in os.listdir("../../"):
#     print(filename)
#
# print(os.curdir, os.pardir)

# os.chdir("../")
# os.chdir("F:\\")
#
# for filename in os.listdir("."):
#     print(filename)


# print(os.cpu_count())

# print(os.path.exists("./4.切片.py"))
#
# print(os.path.isdir("./4.切片.py"), os.path.isdir("./venv"))
#
# print(os.path.isfile("./4.切片.py"), os.path.isfile("./venv"))
#
# print(os.path.abspath("."))
# os.chdir("../../")
# print(os.path.abspath("."))


import math
import time

# print(math)


# print(math.pi)

# print(math.sin(math.pi / 6), math.asin(0.5))
# print(math.cos(math.pi / 3), math.acos(0.5))
# print(math.tan(math.pi / 4), math.atan(1))
# print(math.degrees(math.pi), math.radians(360))

# print(math.ceil(3.45))
# print(math.floor(3.45))
# print(round(3.55))

# print(math.fabs(-10))
# print(math.isinf(math.inf), math.inf > 99999999999999999999, -math.inf < -99999999999999999999999999999999999)


# print(math.sqrt(64), math.pow(3, 4), 3**4)

# # 打开文件 file用于存储打开文件的实例
# file = open("./myfolder/log.txt", mode="r")
# print(file.readable()) # 可读
# content = file.read()
# print(type(content)) #读出来所有内容
# # print(file.readline())
# # print(file.readline())
# # print(file.readline())
# print(file.readlines())
# # 关闭文件
# file.close()


# file = open("./myfolder/log.txt", mode="w")
# # print(file.writable())
# # file.write("hello world\nhi world")
# # file.write("123")
# file.writelines(["123\n", "345\n", "456\n", "456\n"])
# file.close()


# file = open("./myfolder/log.txt", "w")
# print(file.readable(), file.writable())
# # file.write("hello")
# # file.read()
# file.close()


# file = open("./myfolder/1.jpeg", "rb")
# content = file.read()
#
# file2 = open("./myfolder/2.jpeg", "wb")
# file2.write(content)
# file2.close()
#
# file.close()

# file = open("./myfolder/log1.txt", "a")
# file.write(str(time.time())+"\n")
# file.close()


# file = open("./myfolder/log3.txt", "a+")
# print(file.readable(), file.writable())
# file.close()

# 声明一个临时作用域 代码执行完毕作用域相关对象自动释放
# with open("./myfolder/log.txt", "r") as file:
#     print(file.read())



# json  序列化与反序列模块
# 序列化： 将python数据类型 转变为字符串（文件中只能写入字符串）
# 反序列化：将字符串转变为python数据类型
import json

# datas = [
#     {"id": 101, "name": "小马"},
#     {"id": 102, "name": "小王"},
#     {"id": 103, "name": "小张"},
# ]


# with open("./myfolder/abc.txt", "w", encoding="utf8") as f:
#     datas_str = json.dumps(datas)
#     print(type(datas_str), datas_str)
#     f.write(datas_str)


# with open("./myfolder/abc.txt", encoding="utf8") as f:
#     content = f.read()
#     datas = json.loads(content)
#     # print(datas, type(datas))
#     for data in datas:
#         for k, v in data.items():
#             print(k, v)

import pickle

# datas = [
#     {"id": 101, "name": "小马"},
#     {"id": 102, "name": "小王"},
#     {"id": 103, "name": "小张"},
# ]
#
# with open("./myfolder/abc.txt", "wb") as f:
#     data_str = pickle.dumps(datas)
#     f.write(data_str)


# with open("./myfolder/abc.txt", "rb") as f:
#     datas_bytes = f.read()
#     datas = pickle.loads(datas_bytes)
#     for data in datas:
#         for k,v in data.items():
#             print(k, v)


# datas = [
#     {"id": 101, "name": "小马"},
#     {"id": 102, "name": "小王"},
#     {"id": 103, "name": "小张"},
# ]

# with open("./myfolder/abc.txt", "w") as f:
#     datas_str = json.dumps(datas)
#     f.write(datas_str)

# with open("./myfolder/abc.txt", "w") as f:
#     json.dump(datas, f)

# with open("./myfolder/abc.txt", "r") as f:
#     content = f.read()
#     datas = json.loads(content)
#     print(datas)


with open("./myfolder/abc.txt", "r") as f:
    datas = json.load(f)
    print(datas)

